package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.request.RoleAddParam;
import com.xin.di.uav.applet.resp.SysRoleResp;
import com.xin.di.uav.applet.service.RoleService;
import com.xin.di.uav.common.response.IdAndNameResp;
import com.xin.di.uav.common.utils.Rs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/home/role/")
public class SysRoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("list")
    public Rs<SysRoleResp> list(@RequestParam int page, @RequestParam int pageSize
            , @RequestParam(required = false) String serviceRegion) {
        return Rs.success(roleService.list(page, pageSize, serviceRegion));
    }


    @GetMapping("sel-list")
    public Rs<List<IdAndNameResp>> selList(@RequestParam String name) {
        return Rs.success(roleService.selList(name));
    }


    @PostMapping("add")
    public Rs<Boolean> add(@RequestBody @Valid RoleAddParam roleAddParam) {
        return Rs.success(roleService.add(roleAddParam));
    }

    @PostMapping("edit")
    public Rs<Boolean> edit(@RequestBody @Valid RoleAddParam roleAddParam) {
        return Rs.success(roleService.add(roleAddParam));
    }

    @DeleteMapping("delete/{id}")
    public Rs<Boolean> delete(@PathVariable String id) {
        return Rs.success(roleService.delete(id));
    }
}
